<#include "/layout/layout.ftl">
<#import "/layout/macro.ftl" as macro>
<#import "/layout/select.ftl" as my/>
<#assign css>
<style>
</style>
</#assign>
<#assign js>
<script>
	function del(id) {
		layer.confirm('确定删除吗?', {icon: 3, title: '提示'}, function (index) {
			$.ajax({
				type: "POST",
				dataType: "json",
				url: "/address/delete/" + id,
				success: function (res) {
					layer.msg(res.message, {time: 2000}, function () {
						location.reload();
					});
				}
			});
		});
	}

	//tableId,queryId,conditionContainer
	//var userTable;
	var winId="userWin";
	$(function() {
		//init table and fill data
		//userTable = new CommonTable("user_table", "user_list", "searchDiv");

		//button event
		$('button[data-btn-type]').click(function() {
			var action = $(this).attr('data-btn-type');
			var rowId="ceshi";
			switch (action) {
				case 'add':
					modals.openWin({
						winId:winId,
						title:'新增用户地址管理',
						width:'900px',
						url:"/address/edit/ceshi"
					});
					break;
				case 'edit':
					if(!rowId){
						modals.info('请选择要编辑的行');
						return false;
					}
					modals.openWin({
						winId:winId,
						title:'编辑用户地址管理【'+userTable.getSelectedRowData().name+'】',
						width:'900px',
						url:"/address/edit/"+rowId,
					});
					break;
				case 'delete':
					if(!rowId){
						modals.info('请选择要删除的行');
						return false;
					}
					modals.confirm("是否要删除该行数据？",function(){
						ajaxPost(basePath+"/address/delete/"+rowId,null,function(data){
							if(data.success){
								//modals.correct("已删除该数据");
								userTable.reloadRowData();
							}else{
								modals.error("用户地址管理数据被引用，不可删除！");
							}
						});
					})
					break;
			}

		});
		//form_init();
	});
</script>
</#assign>
<@layout title="用户地址管理管理" active="address">
<!-- Content Header (Page header) -->

<!-- Main content -->
<section class="content">
	<!-- Default box -->
	<div class="box box-primary">
		<div class="box-header">
            <form class="form-horizontal form-edit" method="post" action="/address/index" id="form">
                <div class="form-group" style="margin-top:10px;">
                    <div class="col-sm-2">
                        <input  placeholder="请输入用户名" id="userName" name="userName" class="form-control" type="text" value="${search.userName!}" >
                    </div>
                    <div class="col-sm-2">
                        <input  placeholder="请输入地址名称" id="title" name="title" class="form-control" type="text" value="${search.title!}" >
                    </div>
                    <div class="col-sm-2">
                        <input  placeholder="请输入详细地址" id="detail" name="detail" class="form-control" type="text" value="${search.detail!}" >
                    </div>


                </div>

                <div class="form-group" style="margin-top:10px;">
                    <div class="col-sm-2">
                        <input  placeholder="请输入联系人姓名" id="name" name="name" class="form-control" type="text" value="${search.name!}" >
                    </div>
                    <div class="col-sm-2">
                        <input  placeholder="请输入联系人电话" id="phone" name="phone" class="form-control" type="text" value="${search.phone!}" >
                    </div>
                    <div class="col-sm-2">
						<@my.select id="usual" datas=getDict('IS_NOT')  value="${search.usual!}" defaultValue="是否常用地址"/>
                    </div>
                    <div class="btn-group">
                        <button type="submit" class="btn btn-primary" data-btn-type="search">查询</button>
                        <button type="button" class="btn btn-default" data-btn-type="reset" onclick="javascript:$('#form')[0].reset();">重置</button>
                    </div>

                </div>


            </form>


        <@shiro.hasPermission name="system:address:add">
			<a class="btn btn-sm btn-success" href="/address/add">新增</a>
        </@shiro.hasPermission>
		</div>
		<div class="box-body">
			<table class="table table-striped">
				<tr>
					<th>主键</th>
                    <th>用户名</th>
                    <th>地址名称</th>
                    <th>详细地址</th>
                    <th>楼层门牌号</th>
                    <th>姓名</th>
                    <th>联系电话</th>
                    <th>是否常用地址</th>
                    <th>添加时间</th>
					<th>操作</th>
				</tr>
                <#list pageInfo.list as item>
                <tr>
					<td >${item.id!}</td>
                    <td >${item.userName!}</td>
                    <td >${item.title!}</td>
                    <td >${item.detail!}</td>
                    <td >${item.doorplate!}</td>
                    <td >${item.name!}</td>
                    <td >${item.phone!}</td>
                    <td >${convert('IS_NOT',item.usual)!}</td>

					<td >${(item.createAt?string('yyyy-MM-dd HH:mm:ss'))!}</td>
					<td>
					<@shiro.hasPermission name="system:address:detail">
                        <a class="btn btn-sm btn-success" href="/address/detail/${item.id}" data-btn-type="detail">详情</a>
                    </@shiro.hasPermission>
                    <@shiro.hasPermission name="system:address:edit">
                        <a class="btn btn-sm btn-primary" href="/address/edit/${item.id}" data-btn-type="edit">编辑</a>
                    </@shiro.hasPermission>
                    <@shiro.hasPermission name="system:address:delete">
                        <button class="btn btn-sm btn-danger" onclick="del('${item.id}')">删除</button>
                    </@shiro.hasPermission>
					</td>
				</tr>
                </#list>
			</table>
		</div>
		<!-- /.box-body -->
		<div class="box-footer clearfix">
            <@macro.page pageInfo=pageInfo url="/address/index?" />
		</div>
	</div>
	<!-- /.box -->

</section>
<!-- /.content -->
</@layout>
